Skip to content

change m_players in GameRep from Array to std::vector#510

Closed
d-kad wants to merge 1 commit intogambitproject:masterfrom
d-kad:issue_496
Closed

change m_players in GameRep from Array to std::vector#510
d-kad wants to merge 1 commit intogambitproject:masterfrom
d-kad:issue_496

Conversation

@d-kad
Copy link
Copy Markdown
Contributor

@d-kad d-kad commented Apr 22, 2025

Closes #496

@d-kad d-kad requested a review from tturocy April 22, 2025 06:37
Copy link
Copy Markdown
Member

@tturocy tturocy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some opportunities here for taking care of some C++ modernisation - including ways to get rid of a lot of the index-based expressions altogether.

{
Array<int> ns;
for (int pl = 1; pl <= aggPtr->getNumPlayers(); pl++) {
ns.push_back(m_players[pl]->NumStrategies());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is a good opportunity to modernise code by avoiding the use of indices altogether:

for (const auto &player : m_players) {
  ns.push_back(player->NumStrategies());
}


GameStrategy GameAGGRep::GetStrategy(int p_index) const
{
for (int pl = 1; pl <= aggPtr->getNumPlayers(); pl++) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can also be written as a range-based for-loop (as above example)

@@ -246,7 +246,7 @@ int GameBAGGRep::MixedProfileLength() const
{
int res = 0;
for (size_t pl = 1; pl <= NumPlayers(); pl++) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Range-based for loop - or arguably even better std::aggregate to use an STL algorithm.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went for the range-based option as the alternative code (using std::accumulate) looked too bulky and complex

@tturocy
Copy link
Copy Markdown
Member

tturocy commented Apr 23, 2025

Merged at 58f66f5

@tturocy tturocy closed this Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change GameXXXRep::m_players from Gambit::Array to std::vector and move to GameRep::m_players

2 participants